﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Xml.Serialization;

namespace ShapeDemo
{
    public class ASPNETX_ShapeControl
    {
        public CmmnProp CommonProperty { get; set; } 
    }
    
    /// <summary>
    /// 自定义WPF矩形
    /// </summary>
    public class ASPNETX_WPFRect:ASPNETX_Shape
    {
        //public CmmnProp CommonProperty { get; set; } 
        
        public Rectangle RectBody { get; set; }
        
        public Point P1 { get; set; }               //左上角的点
        public Point P2 { get; set; }               //右下角的点

        public ASPNETX_WPFRect()
        {
            CommonProperty = new CmmnProp();
            
            RectBody = new Rectangle();
            P1 = new Point();
            P2 = new Point();
        }
        
        /// <summary>
        /// 宽度
        /// </summary>
        public double Width
        {
            get
            {
                return  Math.Abs(P1.X - P2.X);
            }
            set
            {
                RectBody.Width = value;
            }
        }
        
        /// <summary>
        /// 高度
        /// </summary>
        public double Height
        {
            get
            {
                return Math.Abs(P1.Y - P2.Y);
            }
            set
            {
                RectBody.Height = value;
            }
        }
     
        /// <summary>
        /// 布局-顶
        /// </summary>
        public double Top
        {
            get
            {
                if (P1.Y < P2.Y)
                {
                    return  P1.Y;
                }
                else
                {
                    return  P2.Y;
                }
            }
            set
            {
                RectBody.SetValue(Canvas.TopProperty, value);
            }
        }
        
        /// <summary>
        /// 布局-左
        /// </summary>
        public double Left
        {
            get
            {
                if (P1.X < P2.X)
                {
                    return  P1.X;
                }
                else
                {
                    return P2.X;
                }
            }
            set
            {
                RectBody.SetValue(Canvas.LeftProperty, value);
            }
        }
    }


    /// <summary>
    /// 自定义WPF点
    /// </summary>
    public class ASPNETX_WPFPoint : ASPNETX_Shape
    {
        //public CmmnProp CommonProperty { get; set; }

        public Point PointBody { get; set; }

        public Rectangle PointDrawingBody { get; set; }

        public ASPNETX_WPFPoint()
        {
            CommonProperty = new CmmnProp();

            PointBody = new Point();
            PointDrawingBody = new Rectangle();
        }

        public Rectangle DrawPoint()
        {
            PointDrawingBody.Fill = new SolidColorBrush(Colors.Black);
            PointDrawingBody.Width = 6;
            PointDrawingBody.Height = 6;
            PointDrawingBody.SetValue(Canvas.LeftProperty, PointBody.X - 3);
            PointDrawingBody.SetValue(Canvas.TopProperty, PointBody.Y - 3);
            
            return PointDrawingBody;
        }
    }

    /// <summary>
    /// 自定义WPF线
    /// </summary>
    public class ASPNETX_WPFPolyline : ASPNETX_Shape
    {
        //public CmmnProp CommonProperty { get; set; }

        public Polyline PolylineBody { get; set; }

        public ASPNETX_WPFPolyline()
        {
            CommonProperty = new CmmnProp();

            PolylineBody = new Polyline();
        }
    }

    /// <summary>
    /// 自定义WPF面
    /// </summary>
    [Serializable]
    public class ASPNETX_WPFPolygon : ASPNETX_Shape
    {
        //[XmlElement("CommonProperty")]
        //public CmmnProp CommonProperty { get; set; }

        //[XmlElement("PolygonBody")]
        
        public Polygon PolygonBody { get; set; }

        public ASPNETX_WPFPolygon()
        {
            CommonProperty = new CmmnProp();

            PolygonBody = new Polygon();
        }
    }


    /// <summary>
    /// 自定义WPF圆
    /// </summary>
    public class ASPNETX_WPFEllipse : ASPNETX_Shape
    {
        //public CmmnProp CommonProperty { get; set; }

        public Ellipse EllipseBody { get; set; }
        public Point P1 { get; set; }               //左上角的点
        public Point P2 { get; set; }               //右下角的点

        public ASPNETX_WPFEllipse()
        {
            CommonProperty = new CmmnProp();

            EllipseBody = new Ellipse();
            P1 = new Point();
            P2 = new Point();
        }

        /// <summary>
        /// 宽度
        /// </summary>
        public double Width
        {
            get
            {
                return Math.Abs(P1.X - P2.X);
            }
            set
            {
                EllipseBody.Width = value;
            }
        }

        /// <summary>
        /// 高度
        /// </summary>
        public double Height
        {
            get
            {
                return Math.Abs(P1.Y - P2.Y);
            }
            set
            {
                EllipseBody.Height = value;
            }
        }

        /// <summary>
        /// 布局-顶
        /// </summary>
        public double Top
        {
            get
            {
                if (P1.Y < P2.Y)
                {
                    return P1.Y;
                }
                else
                {
                    return P2.Y;
                }
            }
            set
            {
                EllipseBody.SetValue(Canvas.TopProperty, value);
            }
        }

        /// <summary>
        /// 布局-左
        /// </summary>
        public double Left
        {
            get
            {
                if (P1.X < P2.X)
                {
                    return P1.X;
                }
                else
                {
                    return P2.X;
                }
            }
            set
            {
                EllipseBody.SetValue(Canvas.LeftProperty, value);
            }
        }
    }
}
